<?php

/**
 * Core_Data_Randompassword
 * create random password
 * @author Adrian Stolarski
 */
class Core_Data_Randompassword implements Core_Data_Mainable, Core_Data_Randomable {
    
    public $lower_case = "abcdefghijklmnoprstquwxyz";
    public $uper_case = "ABCDEFGHIJKLMNOPRSTQUWXYZ";
    public $numeric = "0123456789";
    public $special_chars = "`~!@#$%^&*()-_=+[]{};:'\",<.>/?\|";
    public $weight = 9;
    
    /**
     * main()
     * generate random password
     * 
     * @param array $variables
     * @return type $password
     */
    public function main(array $variables = null) {
        //var_dump($variables);
        //die();
        $value = $this->lower_case.$this->uper_case.$this->numeric.$this->special_chars;
        //echo $value;
        //die();
        $password_strlen = $this->weight;
        $password = $this->random_string($value, $password_strlen);
        return $password;
    }
    
    /**
     * random_string()
     * random string generator
     * 
     * @param type $value
     * @param type $weight
     * @return type $password
     */
    public function random_string($value, $weight) {
        //echo $value;
        //die();
        $string_weight = strlen($value);
        //echo $string_weight;
        //echo $weight;
        //die();
        for($char = 0; $char < $weight; $char++){
            $password .= substr($value, rand(0, $string_weight -1), 1); 
        }
        //echo $password;
        //die();
        return $password;
    }

}
